# Inits
require(rio)
require(BayesFactor)
require(dplyr)
library(logr)
set.seed(1234)

# Load data
data<-import("C:/Userdata/Shared/Dofiles/PrelDoFiles/PrelRafael/Rasmussen replication/bfdata.dta")


bf_origsi = regressionBF(diff_orig_conserv ~ diff_edu, data = data %>% filter(complete.cases(diff_edu, diff_orig_conserv)), rscaleCont = "ultrawide")

bf_origei = regressionBF(diff_orig_econlib ~ diff_edu, data = data %>% filter(complete.cases(diff_edu, diff_orig_econlib)), rscaleCont = "ultrawide")

bf_si = regressionBF(diff_conserv ~ diff_edu, data = data %>% filter(complete.cases(diff_edu, diff_conserv)), rscaleCont = "ultrawide")

bf_ei = regressionBF(diff_econlib ~ diff_edu, data = data %>% filter(complete.cases(diff_edu, diff_econlib)), rscaleCont = "ultrawide")

bf_dz_origsi = regressionBF(diff_orig_conserv ~diff_PGI, data = data %>% filter(complete.cases(diff_PGI, diff_orig_conserv)), rscaleCont = "ultrawide")

bf_dz_origei = regressionBF(diff_orig_econlib ~diff_PGI, data = data %>% filter(complete.cases(diff_PGI, diff_orig_econlib)), rscaleCont = "ultrawide")

bf_dz_si = regressionBF(diff_conserv_DZ ~diff_PGI, data = data %>% filter(complete.cases(diff_PGI, diff_conserv_DZ)), rscaleCont = "ultrawide")

bf_dz_ei = regressionBF(diff_econlib_DZ ~diff_PGI, data = data %>% filter(complete.cases(diff_PGI, diff_econlib_DZ)), rscaleCont = "ultrawide")


log <- log_open("C:/Userdata/Shared/Dofiles/PrelDoFiles/PrelRafael/Rasmussen replication/Output/bflog")

log_print("Closer replication analyses")
log_print("Economic ideology")
log_print(bf_origei)
log_print("Social ideology")
log_print(bf_origsi)

log_print("MZ models with new measures")
log_print("Economic ideology")
log_print(bf_ei)
log_print("Social ideology")
log_print(bf_si)

log_print("PGI models with closer replication measures")
log_print("Economic ideology")
log_print(bf_dz_origei)
log_print("Social ideology")
log_print(bf_dz_origsi)

log_print("PGI models with new measures")
log_print("Economic ideology")
log_print(bf_dz_ei)
log_print("Social ideology")
log_print(bf_dz_si)


log_close()